require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')
require('../libs/iconfont/iconfont/iconfont.css')

require('../css/my.less')

//引入axios
const axios = require('axios')

document.addEventListener('DOMContentLoaded', function () {
    //获取元素
    const imgurl = document.querySelector('#imgurl')
    const nickname = document.querySelector('#nickname')
    const times = document.querySelector('#times')
    const calorie = document.querySelector('#calorie')
    const dynamicCount=document.querySelector('#dynamicCount')
    const syn=document.querySelector('#syn')
    // console.log(syn);
    //axios接口地址
    axios.get('http://139.9.177.51:8099/users/mysportsBadge', {
        params: {
            //输入参数
            userId: localStorage.getItem('userId')
        }
    }).then(function (res) {
        //获取数据
        //console.log(res);
        //个人信息数据
        let user = res.data.data.user
        //console.log(user);
        //个人运动数据
        let sport = res.data.data.sports
        //console.log(sport);
        let dynamic=res.data.data.dynamicCount
        //console.log(dynamic);
        
        //判断后台数据是否为空，如果不为空渲染到页面的相应位置
        if (user.imgurl) {
            //图片路径渲染
            imgurl.src = user.imgurl
        }
        if (user.nickname) {
            //昵称渲染
            nickname.textContent = user.nickname
        }
        if(user.sign){
            syn.textContent=user.sign
        }
        // console.log(user.sign);
        if (sport.times) {
            //运动时间渲染
            times.textContent = sport.times
        }
        if (sport.calorie) {
            //运动卡路里渲染
            calorie.textContent = sport.calorie
        }
        //因为后台数据为0条，所有不能用if判断（if判断为0时为false不会执行，所以不需要if判断。其次因为dynamicCount只有一条数据而非一个对象，所以不需要想sport或者user那样user.xxx进行渲染）
            dynamicCount.textContent=dynamic
       
    })

    const btn=document.querySelector('#btn')
    btn.addEventListener('click',function(){

        localStorage.clear()
        location.href='./landing.html'

    })

    let login=document.querySelector('#login')
    login.addEventListener('click',function(){
        location.href='./information.html'
    })
})